package com.example.demo.suanfa_jiegou;

import org.junit.Test;

/**
 * 递归
 */
public
class DiGuiDemo {

    @Test
    public void maxArray() {
        int[] arr = {1, 2, 3, 4};
        int max = maxArray(arr, 0, arr.length - 1);
        System.out.println(max);
    }

    private int maxArray(int[] arr, int L, int R) {
        if (L == R) {
            return arr[L];
        }
        int mid = L + ((R - L) >> 1);
        int lMax = maxArray(arr, L, mid);
        int rMax = maxArray(arr, mid + 1, R);
        return Math.max(lMax, rMax);
    }


}
